/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.qframe.quickc;

import java.lang.annotation.Annotation;
import java.util.HashMap;
import java.util.Set;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.TypeElement;
import org.qframe.quickc.annotations.QHandler;

/**
 *
 * @author gprasad
 */
@SupportedAnnotationTypes(value = {"*"})
@SupportedSourceVersion(SourceVersion.RELEASE_6)
public class QFrameCompiler extends AbstractProcessor {

    private static final HashMap<Class<? extends Annotation>, IAnnotationProcessor> annotationProcessors =
            new HashMap<Class<? extends Annotation>, IAnnotationProcessor>();

    static {
        try {
            annotationProcessors.put(QHandler.class, new QHandlerAnnotationProcessor());
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }

    @Override
    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {

        processClassesForAnnotation(roundEnv, annotations, QHandler.class);
        //processingEnv.getFiler().

        return true;
    }

    private void processClassesForAnnotation(RoundEnvironment roundEnv, Set<? extends TypeElement> annotations, Class<? extends Annotation> annotation) {
        try {
            annotationProcessors.get(annotation).process(annotations, roundEnv, processingEnv);
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }
}
